#pragma once

#include "d3d9.h"
#include "d3dx9.h"
#include "ModelManager.h"

// Add pragma comments so you do not have to change
// the property dependencies
#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")

// Plane structure
struct s_Skybox
{
	// create world matrices for skybox
	D3DXMATRIX	worldMat, scaleMat, rotMat, transMat;
	// Mesh attributes for the world skybox
	ID3DXMesh*			m_pMesh;
	D3DMATERIAL9*		m_pMaterials;
	DWORD				m_dwNumMaterials;
	LPDIRECT3DTEXTURE9*	m_pMeshTextures;
	D3DXVECTOR3			vecPos;
	D3DXVECTOR3			vecRot;
	D3DXVECTOR3			vecScale;
};

class Camera
{
private:
	// Singleton instance
	static Camera* m_CamInstance;
	// Requried matrices
	D3DXMATRIX		worldMat, scaleMat, rotXMat, rotYMat, transMat;
	D3DXMATRIX		m_viewMat;	// Camera view matrix
	D3DXMATRIX		m_projMat;	// Projection matrix (frustum)
	// Required vectors
	D3DXVECTOR3		m_lookAt;	// Direction we're looking
	D3DXVECTOR3		m_upVec;	// Which way is up
	// Attributes for creating the ray
	D3DXMATRIX		m;
	D3DXVECTOR3		vecRayOrigin, vecRayDir;
	D3DXVECTOR3		vecCollisionPoint;	
	// Variables to keep track of the screen size
	int				iScreenHeight;
	int				iScreenWidth;
	// Create the plane structure for skybox
	s_Skybox*			m_pWorldSkybox;
	// Pointer to the D3D Device
	IDirect3DDevice9*	m_Device;
	// Pointer to the ModelManager
	ModelManager*	m_pModelManager;

public:
	Camera(void);
	~Camera(void);

	// Needed in public so other classes can see where the camera is.
	D3DXVECTOR3		m_eyePos;	// Eye position
	// Boundary variables
	float			fXNegBound;
	float			fXBound;
	float			fZNegBound;
	float			fZBound;

	// Singleton functions
	static Camera* GetInstance(void);
	void DeleteInstance(void);
	// Camera functions
	void InitCamera(IDirect3DDevice9* m_Device, int nHeight, int nWidth);
	void LoadSkybox(void);
	void SwitchToBuildCam(void);
	void SwitchToFightCam(void);
	void SwtichToBehindCam(void);
	void UpdateCamera(bool bFightMode, bool bJumpOn);
	void ModifyCameraPos(float deltaTime, float fXChange, float fYChange, float fZChange);
	void SetBoundaries(float fXNeg, float fXPos, float fZNeg, float fZPos);
	// Picking function
	D3DXVECTOR3* CreateRay(POINT pMousePoint, bool bFightMode);
	void RenderWorldPlane(void);
	// Shutdown functions
	void DestroySkybox(void);
};
